/**
 * Copyright (C) 2017-2018 pinganfang, Inc. All Rights Reserved.
 */
package com.pingan.haofang.searchcloud.api.route;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * Collection 路由信息
 * 
 * @author huhailiang937
 * @date 2017年4月7日下午4:28:41
 * @since 1.0.0
 */
public class IndexRoute {

    /**
     * 引擎，0-SOLR，1-ES 默认是 0
     */
    private int engineType = 0;

    /**
     * 存储引擎的host
     */
    private String engineHost;

    /**
     * Collection 路由信息key,比如 新房 “estate_collection”
     */
    private String collectionRouteKey;

    /**
     * Collection 名称，比如 新房 “estate_collection_1704160515”
     */
    private String collectionName;

    /**
     * 生效时间,，比如 20170416011536，表示路由信息生效时间
     */
    private String effectYYMMddHHmmTime;

    /**
     * 全部的endpoints
     */
    private List<Endpoint> endpoints;

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }

    /**
     * @return the collectionRouteKey
     */
    public String getCollectionRouteKey() {
        return collectionRouteKey;
    }

    /**
     * @param collectionRouteKey
     *            the collectionRouteKey to set
     */
    public void setCollectionRouteKey(String collectionRouteKey) {
        this.collectionRouteKey = collectionRouteKey;
    }

    /**
     * @return the collectionName
     */
    public String getCollectionName() {
        return collectionName;
    }

    /**
     * @param collectionName
     *            the collectionName to set
     */
    public void setCollectionName(String collectionName) {
        this.collectionName = collectionName;
    }

    /**
     * @return the effectYYMMddHHmmTime
     */
    public String getEffectYYMMddHHmmTime() {
        return effectYYMMddHHmmTime;
    }

    /**
     * @param effectYYMMddHHmmTime
     *            the effectYYMMddHHmmTime to set
     */
    public void setEffectYYMMddHHmmTime(String effectYYMMddHHmmTime) {
        this.effectYYMMddHHmmTime = effectYYMMddHHmmTime;
    }

    /**
     * @return the endpoints
     */
    public List<Endpoint> getEndpoints() {
        return endpoints;
    }

    /**
     * @param endpoints
     *            the endpoints to set
     */
    public void setEndpoints(List<Endpoint> endpoints) {
        this.endpoints = endpoints;
    }

    /**
     * @return the engineType
     */
    public int getEngineType() {
        return engineType;
    }

    /**
     * @param engineType
     *            the engineType to set
     */
    public void setEngineType(int engineType) {
        this.engineType = engineType;
    }

    /**
     * @return the engineHost
     */
    public String getEngineHost() {
        return engineHost;
    }

    /**
     * @param engineHost
     *            the engineHost to set
     */
    public void setEngineHost(String engineHost) {
        this.engineHost = engineHost;
    }

    /**
     * 
     * @author huhailiang937
     * @date 2017年7月6日上午11:17:07
     * @since 1.0.0
     */
    public static class Endpoint implements Comparable<Endpoint> {

        public Endpoint() {

        }

        public Endpoint buildName(String collectionName) {
            this.setCollectionName(collectionName);
            return this;
        }

        public Endpoint buildEffectTime(Date effectTime) {
            this.setEffectTime(effectTime);
            return this;
        }

        public Endpoint buildEngineHost(String engineHost) {
            this.setEngineHost(engineHost);
            return this;
        }

        public Endpoint buildEngineType(int engineType) {
            this.setEngineType(engineType);
            return this;
        }
        
        /**
         * 引擎，0-SOLR，1-ES 默认是 0
         */
        private int engineType = 0;
        
        /**
         * 存储引擎的host
         */
        private String engineHost;

        /**
         * Collection 名称，比如 新房 “estate_collection_1704160515”
         */
        private String collectionName;

        /**
         * 生效时间,，比如 20170416011536，表示路由信息生效时间
         */
        private Date effectTime;

        /**
         * @return the collectionName
         */
        public String getCollectionName() {
            return collectionName;
        }

        /**
         * @param collectionName
         *            the collectionName to set
         */
        public void setCollectionName(String collectionName) {
            this.collectionName = collectionName;
        }

        /**
         * @return the effectTime
         */
        public Date getEffectTime() {
            return effectTime;
        }

        /**
         * @param effectTime
         *            the effectTime to set
         */
        public void setEffectTime(Date effectTime) {
            this.effectTime = effectTime;
        }

        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Object#hashCode()
         */
        @Override
        public int hashCode() {
            return HashCodeBuilder.reflectionHashCode(this, "effectTime");
        }

        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Object#equals(java.lang.Object)
         */
        @Override
        public boolean equals(Object obj) {
            return EqualsBuilder.reflectionEquals(this, obj, "effectTime");
        }

        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Comparable#compareTo(java.lang.Object)
         */
        @Override
        public int compareTo(Endpoint indexRouteEndpoint) {
            if (indexRouteEndpoint == null || null == indexRouteEndpoint.getEffectTime()) {
                return 0;
            }
            if (null == effectTime) {
                return 0;
            }
            return indexRouteEndpoint.effectTime.compareTo(this.effectTime);
        }

        /**
         * @return the engineHost
         */
        public String getEngineHost() {
            return engineHost;
        }

        /**
         * @param engineHost
         *            the engineHost to set
         */
        public void setEngineHost(String engineHost) {
            this.engineHost = engineHost;
        }

        /**
         * @return the engineType
         */
        public int getEngineType() {
            return engineType;
        }

        /**
         * @param engineType the engineType to set
         */
        public void setEngineType(int engineType) {
            this.engineType = engineType;
        }

    }

}
